<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * @var int
     */
    private $code = 0;

    /**
     * @var array
     */
    private $data = [];

    /**
     * @var string
     */
    private $message = '操作成功';

    protected $pageSize = 10;

    /**
     * @param $param
     * @param $value
     */
    public function set($param, $value)
    {
        $this->$param = $value;
    }


    /**
     * @return array
     * ajax 返回格式
     */
    public function ajaxResponse()
    {
        return [
            'code'=>$this->code,
            'message'=>$this->message,
            'data'=>$this->data
        ];
    }

    /**
     * @var string
     * 短信账户
     */
    private $acount = 'scysjr01';
    /**
     * @var string
     * 短信密码
     */
    private $passwd = 'kU2iC3yK';

    /**
     * @param $param
     * @param $value
     */


    /**
     * @param $mobile
     * @param $code
     * @return array
     * 短信SDK
     */
    public function sendMsg($mobile,$code,$con=null)
    {
        $username = $this->acount;
        $pwd =  $this->passwd;
        $password = md5($username.md5($pwd));
        $content = $con."您的验证码是：".$code."【御顺金融】";
        $url = "http://120.55.248.18/smsSend.do?";
        /*$str = $url."username=$username&password=$password&mobile=$mobile&content=".urlencode($content);
        dd($str);*/
        $param = http_build_query(
            array(
                'username'=>$username,
                'password'=>$password,
                'mobile'=>$mobile,
                'content'=>$content
            )
        );
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_HEADER,0);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$param);
        $result = curl_exec($ch);
        curl_close($ch);
        $this->set('code',$result);
        return $this->ajaxResponse();
    }

}
